/* 
    Squirrel open project
    Copyright (C) 2012  Elias Aran Paul Farhan
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include <squirrel/box.hpp>
Box::Box(Point origin, Point end)
{
	this->origin = origin;
	this->end = end;
}
Box::~Box()
{
	
}
void Box::setPosition(Point origin, Point end)
{
	this->origin = origin;
	this->end = end;
}
bool Box::pointIsIn(Point point)
{
	return ((origin.first <= point.first) && (point.first <= end.first) 
	&& (origin.second <= point.second) && (point.second <= end.second));
}
bool Box::pointIsIn(Point point, Point origin, Point end)
{
	return ((origin.first <= point.first) && (point.first <= end.first) 
	&& (origin.second <= point.second) && (point.second <= end.second));
}
bool Box::squareIsIn(Point origin, Point end)
{
	return (pointIsIn(origin) || pointIsIn(end) || 
	pointIsIn(std::make_pair(origin.first, end.second)) || 
	pointIsIn(std::make_pair(end.first, origin.second)) ||
	pointIsIn(this->origin, origin, end) || 
	pointIsIn(this->end, origin, end) ||
	pointIsIn(std::make_pair(this->origin.first, this->end.second), origin, end)||
	pointIsIn(std::make_pair(this->end.first, this->origin.second), origin, end)||
	((this->origin.first <= origin.first)&&(this->end.first >= origin.first)&&
	(this->origin.first <=end.first)&&(this->end.first >= end.first)&&
	(origin.second <= this->origin.second)&&(end.second >= this->origin.second)&&
	(origin.second <= this->end.second)&&(end.second >= this->end.second))||
	((origin.first <= this->origin.first)&&(end.first >= this->origin.first)&&
	(origin.first <=this->end.first)&&(end.first >= this->end.first)&&
	(this->origin.second <= origin.second)&&(this->end.second >= origin.second)&&
	(this->origin.second <= end.second)&&(this->end.second >= end.second)));
}
bool Box::BoxIsIn(Box* b)
{
	return (squareIsIn(b->getOrigin(), b->getEnd()));
}
Point Box::getOrigin()
{
	return origin;
}
Point Box::getEnd()
{
	return end;
}
